<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * 学校相关的操作
 *
 * @author YL-Z0016
 */
class SchoolModel {
    /**
     *添加一个学校
     * @param type $name
     * @param type $type
     * @param type $pid
     * @param type $cid
     * @param type $addr
     * @return type
     */
    public function addSchool($name,$type,$pid,$cid,$addr){
        $set = array();
        $set['Fname'] = $name;
        $set['Ftype'] = $type;
        $set['Fprovinceid'] = $pid;
        $set['Fcityid'] = $cid;
        $set['Faddr'] = $addr;
        $db = getDB();
        return $db->insertTable('t_school',$set);

    }
    /**
     *搜索一个学校
     */
    public function searchSchoolByName($name){
        $sql = srprintf("SELECT * FROM t_school WHERE MATCH (Fname) AGAINST ('%s')",$name);
        $db = getDB();
        return $db->get_results($sql);
    }
    /**
     *检查学校名字是否存在
     * @param type $cid
     */
    public function getSchoolByName($name){
        $sql = srprintf("SELECT * FROM t_school WHERE Fname='%s'",$name);
        $db = getDB();
        return $db->get_row($sql);
    }
    /**
     *添加一个学院
     * @param type $scoolid
     * @param type $name
     * @param type $type
     * @param type $pid
     * @param type $cid
     * @param type $addr
     * @return type
     */
    public function addCollege($scoolid,$name,$type,$pid,$cid,$addr){
        $set = array();
        $set['Fschoolid'] = $scoolid;
        $set['Fname'] = $name;
        $set['Ftype'] = $type;
        $set['Fprovinceid'] = $pid;
        $set['Fcityid'] = $cid;
        $set['Faddr'] = $addr;
        $db = getDB();
        return $db->insertTable('t_college',$set);
    }
    /**
     *添加一个系信息
     * @param type $collegeid
     * @param type $name
     * @return type
     */
    public function addDepartment($collegeid,$name){
        $set = array();
        $set['Fcollegeid'] = $collegeid;
        $set['Fname'] = $name;
        $db = getDB();
        return $db->insertTable('t_department',$set);
    }
    /**
     *添加一个专业
     * @param type $name
     */
    public function addMajor($name){
        $set = array('Fname' => $name);
        $db = getDB();
        return $db->insertTable('t_major',$set);
    }
    /**
     *添加一个班级
     * @param type $schoolid
     * @param type $name
     * @param type $start
     * @param type $end
     * @param type $collegeid
     * @param type $departmentid
     * @param type $majorid
     */
    public function addClass($schoolid,$name,$start,$end,$collegeid = 0,$departmentid = 0,$majorid =0 ){
        $set = array();
        $set['Fschoolid'] = $schoolid;
        $set['Fcollegeid'] = $collegeid;
        $set['Fdepartmentid'] = $departmentid;
        $set['Fmajorid'] = $majorid;
        $set['Fstart'] = $start;
        $set['Fend'] = $end;
        $set['Fname'] = $name;
        $db = getDB();
        return $db->insertTable('t_class',$set);
    }

    /**
     *获取学校的全部院
     * @param type $cid
     */
    public function getCollegeByScollid($cid){
        $db = getDB();
        $rs = $db->get_results(sprintf('SELECT * FROM t_college WHERE Fschoolid=%d',$cid));
        if($rs){
            return $rs;
        }
        return array();
    }
    /**
     *根据院获取系信息
     * @param type $cid
     */
    public function getDepartmentByCollegeId($cid){
        $db = getDB();
        $rs = $db->get_results(sprintf('SELECT * FROM t_department WHERE Fcollegeid=%d',$cid));
        if($rs){
            return $rs;
        }
        return array();
    }
    /**
     *根据学校id获取班级信息
     * @param type $cid
     */
    public function getClassBySchoolId($cid){
        $db = getDB();
        $rs = $db->get_results(sprintf('SELECT * FROM t_class WHERE Fschoolid=%d',$cid));
        if($rs){
            return $rs;
        }
        return array();
    }
    /**
     *根据学院id获取班级信息
     * @param type $cid
     * @return type
     */
    public function getClassByCollegeId($cid){
        $db = getDB();
        $rs = $db->get_results(sprintf('SELECT * FROM t_class WHERE Fcollegeid=%d',$cid));
        if($rs){
            return $rs;
        }
        return array();
    }
    /**
     *根据系获取班级信息
     * @param type $did
     * @return type
     */
    public function getClassByDepartmentId($did){
        $db = getDB();
        $rs = $db->get_results(sprintf('SELECT * FROM t_class WHERE Fdepartmentid=%d',$did));
        if($rs){
            return $rs;
        }
        return array();
    }

}

?>
